﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
namespace SLLottery.Common
{
    public class BetCountCalc
    {
        //正向
        public static int GetBetCount(ListBox listbox, PlayType type, bool isWriten, string radioText)
        {
            int NumCount = 0;
            int temp = 0;
            switch (type)
            {
                //===============SSC=================
                #region SSC
                case PlayType._3xZhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            string[] nums = item.Content.ToString().Split(',');
                            NumCount += nums[0].Length * nums[1].Length * nums[2].Length;
                        }
                    }
                    break;
                case PlayType._3xZux:
                    if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            if(item.Content.ToString().ToCharArray().Distinct().Count()==3)
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                            else if (item.Content.ToString().ToCharArray().Distinct().Count() == 2)
                                NumCount += 3;
                            else
                                NumCount += 1;
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Threecalc(item.Content.ToString().Length);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                            }
                        }
                    }
                    break;
                case PlayType._2xZhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            string[] nums = item.Content.ToString().Split(',');
                            NumCount += nums[0].Length * nums[1].Length;
                        }
                    }
                    break;
                case PlayType._2xZux:
                    if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            if (item.Content.ToString().ToCharArray().Distinct().Count() == 2)
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            else
                                NumCount += 1;
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                    }
                    break;
                case PlayType._H1Zhix:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums[0].Length;
                    }
                    break;
                case PlayType._Bddw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums[0].Length;
                    }
                    break;
                case PlayType._Ddw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += (
                              nums[0].Length
                            + nums[1].Length
                            + nums[2].Length
                            + nums[3].Length
                            + nums[4].Length
                            );
                    }
                    break;
                case PlayType._R3Zhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            temp = 0;
                            string[] nums = item.Content.ToString().Split(',');
                            foreach (string num in nums)
                            {
                                if (num.Trim() != string.Empty)
                                    temp = (num.Length * (temp == 0 ? 1 : temp));
                            }
                            NumCount += temp;
                        }
                    }

                    break;
                case PlayType._R3Zux:
                    if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            if (item.Content.ToString().ToCharArray().Distinct().Count() == 3)
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                            else if (item.Content.ToString().ToCharArray().Distinct().Count() == 2)
                                NumCount += 3;
                            else
                                NumCount += 1;
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Threecalc(item.Content.ToString().Length);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                            }
                        }
                    }
                    break;
                case PlayType._R2Zhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            temp = 0;
                            string[] nums = item.Content.ToString().Split(',');
                            foreach (string num in nums)
                            {
                                if (num.Trim() != string.Empty)
                                    temp = (num.Length * (temp == 0 ? 1 : temp));
                            }
                            NumCount += temp;
                        }
                    }
                    break;
                case PlayType._R2Zux:
                   if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            if (item.Content.ToString().ToCharArray().Distinct().Count() == 2)
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            else
                                NumCount += 1;
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                    }
                    break;
                case PlayType._Rydw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += (
                              nums[0].Length
                            + nums[1].Length
                            + nums[2].Length
                            + nums[3].Length
                            + nums[4].Length
                            );
                    }
                    break;
                case PlayType._Rbdw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums[0].Length;
                    }
                    break;
                #endregion
                //================3D=================
                #region 3D
                case PlayType._3DZhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            string[] nums = item.Content.ToString().Split(',');
                            NumCount += nums[0].Length * nums[1].Length * nums[2].Length;
                        }
                    }
                    break;
                case PlayType._3DZux:
                    if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Threecalc(item.Content.ToString().Length);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 3);
                            }
                        }
                    }
                    break;
                case PlayType._3D2xZhix:
                    if (isWriten)
                    {
                        return listbox.Items.Count;
                    }
                    else
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            string[] nums = item.Content.ToString().Split(',');
                            NumCount += nums[0].Length * nums[1].Length;
                        }
                    }
                    break;
                case PlayType._3D2xZux:
                    if (isWriten)
                    {
                        for (int i = 0; i < listbox.Items.Count; i++)
                        {
                            ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                            NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                        }
                    }
                    else
                    {
                        if (radioText.IndexOf("组三") > -1 || radioText.IndexOf("组二") > -1)
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < listbox.Items.Count; i++)
                            {
                                ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                                NumCount += Sixcalc(item.Content.ToString().Length, item.Content.ToString().Length - 2);
                            }
                        }
                    }
                    break;
                case PlayType._3DH1Zhix:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums[0].Length;
                    }
                    break;
                case PlayType._3DBddw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums[0].Length;
                    }
                    break;
                case PlayType._3DDdw:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += (
                              nums[0].Length
                            + nums[1].Length
                            + nums[2].Length
                            );
                    }
                    break;
                #endregion
                //=================SSQ===============
                #region SSQ
                case PlayType._SSQRed:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums.Length;
                    }
                    break;
                case PlayType._SSQBlue:
                    for (int i = 0; i < listbox.Items.Count; i++)
                    {
                        ListBoxItem item = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items[i]));
                        string[] nums = item.Content.ToString().Split(',');
                        NumCount += nums.Length;
                    }
                    break;
                #endregion
            }
            return NumCount;
        }
        public static int GetJieCheng(int num)
        {
            int result = 1;
            for (int i = 1; i <= num; i++)
            {
                result *= i;
            }
            return result;
        }
        //逆向
        public static int GetBetCount(String nums, PlayType type)
        {
            int NumCount = 0;
            switch (type)
            {
                case PlayType.NSSCBdw:
                    NumCount = nums.Length;
                    break;
                case PlayType.N3DBdw:
                    NumCount = nums.Length;
                    break;
                case PlayType.NSSQBlue:
                    NumCount = nums.Split(',').Length;
                    break;
                case PlayType.NSSQRed:
                    NumCount = nums.Split(',').Length;
                    break;
            }
            return NumCount;
        }
        public static int Sixcalc(int numLength, int nums)
        {
            if (numLength > nums)
                return numLength * Sixcalc(numLength - 1, nums);
            else
                return 1;
        }
        public static int Threecalc(int numLength)
        {
            return (numLength * (numLength - 1) * 1) * 3;
        }
        public static int Twocalc(int numLength)
        {
            return (numLength * (numLength - 1));
        }
    }
}
